package edu.infomatik.tundra.model;

import java.util.Locale;
import org.apache.tapestry5.ValueEncoder;

public class LocaleEncoder implements ValueEncoder<Object> {

	public String toClient(Object obj) {
		Locale loc = (Locale) obj;
		if (loc.getLanguage().equals("sr_CS")){
			loc = new Locale("sr");
		}
		return loc.getLanguage();
	}

	public Object toValue(String str) {
		if (null==str) {
			Locale mainloc;
			if (Locale.getDefault().getLanguage().equals("sr_CS"))
				mainloc=new Locale("sr");
			else mainloc = Locale.getDefault();
			str=mainloc.getLanguage();
		}
		return new Locale(str);
	}
}